#include <QtGui/QApplication>
#include <QTextCodec>
#include "AutoTest.h"

#include <QtGui>
#include <QtNetwork>

#include "SqlInterface.h"
#include <QSqlQuery>
#include <QDebug>

#include <QFile>
#include <QTextStream>

#include "Notifier.h"

#ifdef DEBUG_LOG
void customMessageHandler(QtMsgType type, const char *msg)
{
    QString txt;
    switch (type) {
        case QtDebugMsg:
            txt = QString("Debug: %1").arg(msg);
            break;

        case QtWarningMsg:
            txt = QString("Warning: %1").arg(msg);
            break;
        case QtCriticalMsg:
            txt = QString("Critical: %1").arg(msg);
            break;
        case QtFatalMsg:
            txt = QString("Fatal: %1").arg(msg);
            abort();
    }

    QFile outFile(DEBUG_LOG);
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << txt << endl;
}
#endif

int main(int argc, char *argv[])
{
    QTextCodec *codec = QTextCodec::codecForName("UTF8");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForLocale(codec);

#ifdef DEBUG_LOG
    QFile cleanFile(DEBUG_LOG);
    cleanFile.open(QIODevice::WriteOnly);
    cleanFile.close();
    qInstallMsgHandler(customMessageHandler);
#endif

    // прогон тестов
    AutoTest::run(argc, argv);

    // запуск приложения
    QApplication app(argc, argv);

    Notifier notifier;

//    Event event(EventString("20110707", "YYYYMMDD"));
//    event.setName("transferred event");
//    event.setDefinition("some transferred event text bla bla bla");

//    Event event2(EventString("20110808", "YYYYMMDD"));
//    event2.setName("second event");
//    event2.setDefinition("some second event text bla bla bla");

//    NotifyWindow notify;
//    notify.addEvent(event);
//    notify.addEvent(event2);

    return app.exec();
}
